#ifndef  __CONFMGR_H__
#define  __CONFMGR_H__

#include "define.h"
#include "mempool.h"
#include "commandTree.h"
#include "server.h"
#include <ctype.h>


class commandTree;

//配置管理类;
struct configmgr_st{
	char *configname;
	FILE *file;	
	std::multimap<int,int > keymap;
	std::multimap<int,char *> confmap;
};

namespace CONFMGR
{
	static const char * CONFIGFILENAME = "system.conf";
	static const int CONFIGFILENAMELEN = strlen(CONFIGFILENAME);
}

//配置域索引,
enum configKey{
	SYSTEM_CONFIG = 0,
	THREAD_CONFIG,
	LOG_CONFIG,
	CMD_CONFIG
};



//配置管理类;
class confMgr
{
	public:
		~confMgr(){};
		static confMgr * getInstance();
		static int getConfValue(int type, void *arg, confMgr *conf);  //获取配置域的值;
		int init(const char *path); //初始化接口;
		inline commandTree & getConfMgr() { return this->cmd; }
		inline struct configmgr_st & getConfOpt(){ return this->conf; }
	private:
		struct configmgr_st conf;
		static confMgr * instance;
		int readConfFile(const char *path);
		int getConfigKeyAndValue(char *buf);
		int formatReadFromConf(char *buf, char *temp);
		int setConfigKey(char *option);
		int setOptionConfigKeyAndValue(char *option, char *value, size_t len, int keyindex);
		confMgr(){};
		class Garbge{
			public:
				~Garbge()
				{ 
					if( NULL != confMgr::instance){
						delete confMgr::instance;	
					}
				}
		};
		MemPool mem;
		commandTree cmd;
		Garbge garbge; //垃圾回收类;
};

#endif 
